package org.yn.mkt.controller;

import org.yn.mkt.service.IClueActivityService;
import org.yn.mkt.domain.ClueActivity;
import org.yn.mkt.query.ClueActivityQuery;
import org.yn.base.util.AjaxResult;
import org.yn.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.yn.auth.annotation.PermissionAnnotation;
import java.util.List;

@PermissionAnnotation(name="clueActivity管理",descs = "clueActivity管理")
@Api("clueActivity管理接口")
@RestController
@RequestMapping("/clueActivity")
public class ClueActivityController {
    @Autowired
    public IClueActivityService clueActivityService;


    /**
     * 保存和修改公用的
     * @param clueActivity  传递的实体
     * @return Ajaxresult转换结果
     */
    @PermissionAnnotation(name="保存和修改ClueActivity",descs = "保存和修改ClueActivity")
    @ApiOperation(value = "保存和修改")
    @PostMapping
    public AjaxResult updateOrInsert(@RequestBody ClueActivity clueActivity){
        try {
            if( clueActivity.getId()!=null)
                clueActivityService.update(clueActivity);
            else
                clueActivityService.insert(clueActivity);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("保存对象失败！"+e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @PermissionAnnotation(name="删除ClueActivity",descs = "删除ClueActivity")
    @ApiOperation(value = "删除")
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            clueActivityService.delete(id);
            return AjaxResult.success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.error("删除对象失败！"+e.getMessage());
        }
    }
	
    //获取用户
    @PermissionAnnotation(name="获取单个ClueActivity",descs = "获取单个ClueActivity")
    @ApiOperation(value = "获取单个ClueActivity")
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable("id") Long id)
    {
        try {
            ClueActivity clueActivity = clueActivityService.selectById(id);
            return AjaxResult.success(clueActivity);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取一个失败！"+e.getMessage());
        }
    }


    /**
    * 查看所有的XX信息
    * @return
    */
    @PermissionAnnotation(name="获取所有ClueActivity",descs = "获取所有ClueActivity")
    @ApiOperation(value = "获取所有ClueActivity")
    @GetMapping
    public AjaxResult selectAll(){

        try {
            List< ClueActivity> list = clueActivityService.selectAll();
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取所有失败！"+e.getMessage());
        }
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageInfo 分页对象
    */
    @PermissionAnnotation(name="分页查询ClueActivity",descs = "分页查询ClueActivity")
    @ApiOperation(value = "分页查询ClueActivity")
    @PutMapping
    public AjaxResult queryPage(@RequestBody ClueActivityQuery query)
    {
        try {
            PageInfo<ClueActivity> pageInfo = clueActivityService.queryPage(query);
            return AjaxResult.success(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取分页数据失败！"+e.getMessage());
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PermissionAnnotation(name="批量删除ClueActivity",descs = "批量删除ClueActivity")
    @ApiOperation(value = "批量删除ClueActivity")
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        try {
                clueActivityService.batchDelete(ids);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("批量删除失败"+e.getMessage());
        }
    }
}
